﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NetDon.OA.Interface;
using NetDon.OA.Interface.CRM;
using NetDon.OA.Interface.eLogistics;
using NetDon.Utilities;

namespace NetDon.OA.Portal.eLogisticsQuery
{
    [Navigation("报表查询", "利润查询")]
    public partial class ProfitQueryPage : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                txtReceiptInfoActualResponseDateStart.Text =
 DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd");
                txtReceiptInfoActualResponseDateEnd.Text =
    DateTime.Now.ToString("yyyy-MM-dd");
                ddlCompany.InsertEmptyItem(ListEmptyType.Select);
 
                if (!this.IsSuperRoles())
                {
                    ddlCompany.SelectedValue = CurrentApplicationContext.CompanyId.ToString();
                    ddlCompany.Enabled = false;
                }
            }
        }

 
 
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            HttpContext.Current.Session["ProfitQuery"] = GetSearchCriteria();
            this.ScriptStartup("search();");

        }
        protected RevenueMachineAccountSearchCriteria GetSearchCriteria()
        {
            var criteria = new RevenueMachineAccountSearchCriteria { };

            if (!MiscUtilities.IsNullOrEmpty(ddlCompany.SelectedValue))
            {
                criteria.AreaId = ddlCompany.SelectedValue.ToGuid();
            }

            DateTime? dateStart = null, dateEnd = null;
            if (!string.IsNullOrEmpty(txtReceiptInfoActualResponseDateStart.Text.Trim()))
            {
                dateStart = DateTime.Parse(txtReceiptInfoActualResponseDateStart.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtReceiptInfoActualResponseDateEnd.Text.Trim()))
            {
                dateEnd = DateTime.Parse(txtReceiptInfoActualResponseDateEnd.Text.Trim());
            }
            if (dateStart.HasValue || dateEnd.HasValue)
            {
                criteria.ReceivingOrderDate = new Range<DateTime?>(dateStart, dateEnd);
            }




            if (!MiscUtilities.IsNullOrEmpty(ddlRouteTypeId.SelectedValue.ToGuid()))
            {
                criteria.RouteTypeId = ddlRouteTypeId.SelectedValue.ToGuid();
            }


            return criteria;


        }

    }
}